class Solution:
    def hasAllCodes(self, s: str, k: int) -> bool:
        length = 2**k - 1
        array = [0 for _ in range(length + 1)]
        for i in range(len(s) - k + 1):
            substring = s[i:i + k]
            val = int(substring, 2)
            array[val] = 1
        for i in range(len(array)):
            if array[i] == 0:
                return False
        return True
